2015-02-11 36 views
0

所以我運行一個擴展UnityPlayerActivity的Java插件。我成功覆蓋了onCreate函數。唯一的問題是當我嘗試獲取意向數據時,它的空值。我要查找的數據是觸發意圖的網址。getIntent()。getData()== null爲統一應用程序

package com.company.androidlink; 

import java.net.URL; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import com.unity3d.player.*; 

public class Main extends UnityPlayerActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Intent intent = getIntent(); 
      uri = intent.getData(); 
      url = new URL(uri.getScheme(), uri.getHost(), uri.getPath()); 
    } 
} 

清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.company.androidlink" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="9" 
     android:targetSdkVersion="21" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".Main" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.VIEW" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

回答

1

我公司開發的插件在幾個月前到文本發送到Unity3D應用。該方法,這是在根系活力(相當於你的「主」)如下:

public static String getExtraText() { 
    String extraText = ""; 

    // Store extra parameter for later. 
    Intent intent = UnityPlayer.currentActivity.getIntent(); 

    if (intent != null) { 
     String action = intent.getAction(); 
     String type = intent.getType(); 

     if (action.equals(Intent.ACTION_VIEW) && type != null) { 
      if (type.equals("text/plain")) { 
       extraText = intent.getStringExtra(Intent.EXTRA_TEXT); 
       DebugBridge.log_d("Extra Text: " + extraText); 
      } else { 
       DebugBridge.toast("Unknown MIME type"); 
      } 
     } 
    } 

    return extraText; 
} 

我沒有得到啓動的文本,在需要的時候從Unity應用程序只是調用「getExtraText」(以通常開始)。

這是我從另一個Android原生的測試應用程序將數據發送到統一的方式:

boolean sendMessageToApp(String message, String appName) { 
    ComponentName name = findNativeApp(appName); 

    if (name != null) { 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setComponent(name); 
     intent.addCategory(Intent.CATEGORY_LAUNCHER); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
     intent.setType("text/plain"); 
     intent.putExtra(Intent.EXTRA_TEXT, message); 

     startActivity(intent); 
     return true; 
    } 
    return false; 
} 
相關問題