我正在尝试将Device_ID从一个应用程序发送到另一个应用程序。当按下按钮发送数据时,App_One停止工作。
当我改变"行动"从ACTION_SEND到ACTION_VIEW。 App_ONE工作正常,但App_two不会显示任何结果。
APP_ONE:
public class MainActivity extends AppCompatActivity {
@TargetApi(Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
TelephonyManager tel = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String imei = "";
if(tel.getImei() != null){
imei = tel.getImei();
}else {
imei = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(imei);
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra("Data", imei);
startActivity(i);
}
});
}
}}
APP_TWO:
清单:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="andoid.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
JAVA文件:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bundle i = getIntent().getExtras();
if(i != null){
String data = i.getString("Data");
TextView tv = (TextView) findViewById(R.id.textView);
tv.setText(data);
}
}}