2011-10-07 7 views
4

私はUnityで新しく、本当にアンドロイドの活動から統合アプリケーションを始める方法を理解していません。 ウィジェットが必要な場合があります(たとえば、SMSを受け取ったときなど)。また、ユニティアプリケーションを開始するときにクリックするとウィジェットが必要です。ウィジェットとユニティプロジェクトでは問題はありません。しかし、私はどのようにアンドロイドプロジェクトから団結を開始するのか分からない。アンドロイドの活動からUnityアプリケーションを起動するには?

+0

を作成します。 –

+0

ありがとう、私はgetLaunchIntentForPackage( "package_name")を使用しました。 Unityアプリケーションのパッケージ名を知るためには、InspectorのOtherSettings/BundleIdentifierでBuildSettings/PlayerSettingsを見ます。それは動作します:) – user966562

答えて

0

あなたは主な活動はUnityPlayerActivity(Android上でユニティPlayerのメインループをcontroll)

public class MainActivity extends UnityPlayerActivity implements MyFunction { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
    } 

    @Override 
    protected void onStop() { 
     super.onStop(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
    } 


} 

ここでは、私はウィジェットボタンからアプリケーションを起動して、それを呼び出しdocument

0

で拡張することができます私に役立ちます。 onUpdateウィジェットメソッドからUpdateWidgetButtonsAction()を呼び出し、PendingIntentをonClickに設定します。その後、

private void UpdateWidgetButtonsAction(Context context, AppWidgetManager appWidgetManager, int widgetID) 
    { 
     RemoteViews widgetView = new RemoteViews(context.getPackageName(), R.layout.widget_layout); 
     widgetView.setOnClickPendingIntent(R.id.MyButtonImage, getPendingSelfIntent(context, "ACTION_LOAD_APP")); 
     appWidgetManager.updateAppWidget(widgetID, widgetView); 
    } 

あなたのアプリから別のアプリを起動したい場合、あなたはそのパッケージ名を通して他のアプリを起動することができますACTION_LOAD_APPアクションを受け取るBroadcastReciever、およびstartActivity

public class WidgetBroadcastReceiver extends BroadcastReceiver 
{ 

@Override 
public void onReceive(Context context, Intent intent) { 

    LogCollector.Log("WidgetBroadcastReceiver " + intent.getAction()); 
    if(ACTION_LOAD_APP.equals(intent.getAction())) 
    { 
     Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("UNITY_PACKAGE_NAME"); 
     context.startActivity(launchIntent); 
    } 
} 

}

関連する問題