android静态intent
Posted 81192
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android静态intent相关的知识,希望对你有一定的参考价值。
1.manifest中注册
在Activity中注册,如下:
注:此为必须存在的
<intent-filter>
<action android:name="action.action.action1"/>
<action android:name="action.action.action2"/>
<action android:name="action.action.action3"/>
<action android:name="action.action.action4"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Intent intent = new Intent(action);
context.startActivity(intent);
也可以使用命令adb shell am start -a action.action.action1测试
Intent receiverIntent = getIntent();
String action =receiverIntent.getAction();
或者
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
intentResult=intent.getStringExtra(ReceiverTag);
if(intentResult==null || intentResult == "")
{
intentResult=defaultIntentResult;
}
Log.d(Tag,"Intent result:"+intentResult);
}
public static AndroidJavaObject GetActivity()
{
AndroidJavaClass jc = new AndroidJavaClass(unityPlayerClass);
if (jc == null)
{
Debug.LogErrorFormat("Failed to get Unity Player class, {0}", unityPlayerClass);
return null;
}
AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity");
if (activity == null)
{
Debug.LogError("Failed to obtain Android Activity from Unity Player class.");
return null;
}
return activity;
}
private AndroidJavaObject GetIntent()
{
AndroidJavaObject activity = GetActivity();
if (activity != null)
{
return activity.Call<AndroidJavaObject>("getIntent");
}
return null;
}
public string GetIntentMessage()
{
string result = "";
AndroidJavaObject intent = GetIntent();
if (intent == null)
{
Debug.Log("Get null intent");
return result;
}
try
{
result = intent.Call<string>("getAction");
Debug.Log("Get action result:" + result);
}
catch(Exception ex)
{
Debug.Log("Exception while getting action:" + ex.ToString());
}
return result;
}
以上是关于android静态intent的主要内容,如果未能解决你的问题,请参考以下文章