我尝试在Android项目中实现共享按钮,如this video所示。
<Button
android:id="@+id/shareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnClicked"
android:text="@string/share" />
public void btnClicked(View v){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String shareBody = "Length: " + jump.length + "Time: " + jump.getTime();
String shareSub = "I just jumped with my " + jump.Sport.toString();
shareIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
shareIntent.putExtra(Intent.EXTRA_TEXT,shareBody);
startActivity(Intent.createChooser(shareIntent,"Share Jump"));
}
但是,按我的按钮时会收到此错误消息。
2019-03-04 19:23:41.130 7911-7911/com.google.android.apps.messaging E/FirebaseInstanceId: Failed to start service while in background: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=com.google.android.apps.messaging cmp=com.google.android.apps.messaging/com.google.firebase.iid.FirebaseInstanceIdService (has extras) }: app is in background uid UidRecord{8e293ee u0a55 RCVR idle change:idle|uncached procs:1 seq(0,0,0)}
我想知道如何解决该问题。
谢谢!