2012-02-10 18 views
0

我很新到Android,我在.NET幾年 我試圖創建將啓動其他應用程序,同時應用程序被編碼將一些數據傳遞給它。 我一直聊天到其他應用程序的開發者,他說單爲Android,如何使數據傳遞的意圖

Following is what I wrote in the AndroidManifest.xml: 

     <activity android:name=".EmulatorActivity" 
      <intent-filter> 
       <action android:name="android.intent.action.VIEW" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
       <data android:scheme="file" /> 
       <data android:mimeType="application/x-n64-rom" /> 
      </intent-filter> 
     </activity> 

You should set the Intent URL to something like 'file://path/rom_file', and set its mime type to 'application-x-n64-rom'. 

我不知道如何做到這一點,雖然,我可以成功地推出使用

Intent intent = new Intent(Intent.ActionMain); 
      intent.SetComponent(new ComponentName("com.androidemu.n64", "com.androidemu.n64.MainActivity")); 
      intent.SetFlags(ActivityFlags.NewTask); 
      StartActivity(intent); 

,但如果他的申請我改變ActionMain到和的ActionView到MainActivity它EmulatorActivity試圖火起來,但崩潰 我也沒有想到如何通過變量:)我試過很多的組合,但知道的想法,我要去哪裏錯了 文件名我想通過的是sd卡的根目錄n64.zip

我試過 intent.PutExtra(Intent.ExtraStream,Android.Net.Uri.Parse(「file://sdcard/n64.zip」));

感謝

斯圖

回答

0

你可以試試這個,看看它的工作:

Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW); 
myIntent.setDataAndType(Uri.fromFile("filepath"), "application/x-n64-rom"); 
startActivity(myIntent); 
+0

我沒有得到重載需要2個參數爲Android.Net.Uri.FromFile – Stu1983 2012-02-11 00:06:50

+0

對不起,有一個括號丟失。現在應該工作。 – 2012-02-11 00:31:17

0

需要更多信息。它在哪裏崩潰?

爲你的意圖的構造應該是新的意圖(Intent.ACTION_MAIN)。我不知道Intent.ActionMain是什麼,除非它是你正在使用的開發環境的一部分。

您不能隨意更改intent.SetComponent()。組件包和類名必須 完全匹配其他活動。

+0

我使用的是單聲道的Android,其高清Intent.ActionMain但我認爲對應於ACTION_MAIN。我的應用程序不會崩潰,它是我嘗試啓動的應用程序出現,然後立即崩潰。 – Stu1983 2012-02-11 00:01:44

相關問題