2015年10月13日 星期二

Android app intent other app 從一個App啟動另一個App特定頁面,附帶傳值

1.在App1加入程式碼
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.xxxx.xxxx","com.xxxx.xxxx.SpecialMainActivity")); //包裹名稱,要開啟的頁面
intent.putExtra("value", "test"); //要傳送的值
startActivity(intent);
2.在App2的AndroidManifest.xml加入

        
            
            
                
            
            
        
3.在App2加入接收程式碼
Intent intent = getIntent();
if (intent.hasExtra("value")) {
 String value= intent.getStringExtra("value");
 Log.i("value", value+"");
}else{
 Log.i("value", "null");
}
參考連結:
http://stackoverflow.com/questions/3872063/launch-an-application-from-another-application-on-android