Android 活动没有';单击通知时无法启动
我在我的应用程序中创建了一个通知设置。当用户单击该通知时,应该会打开一个活动Android 活动没有';单击通知时无法启动,android,android-activity,notifications,Android,Android Activity,Notifications,我在我的应用程序中创建了一个通知设置。当用户单击该通知时,应该会打开一个活动Coding。但事实并非如此。当我查看电话日志(在android studio的控制台中)时,其中有一些类似的内容: 10-19:18:14.59888-1437/?W/ActivityManager:权限拒绝:启动意图{flg=0x1000c000 cmp=com.defcomdevs.invento16/.Coding bnds=[0874][10801060]}从null(pid=-1,uid=10169)开始,而
Coding
。但事实并非如此。当我查看电话日志(在android studio的控制台中)时,其中有一些类似的内容:
10-19:18:14.59888-1437/?W/ActivityManager:权限拒绝:启动意图{flg=0x1000c000 cmp=com.defcomdevs.invento16/.Coding bnds=[0874][10801060]}从null(pid=-1,uid=10169)开始,而不是从uid 10185导出
我不明白那是什么?
我的通知代码是:
public class AlarmReceiver extends BroadcastReceiver {
static int notifyId=1;
@Override
public void onReceive(Context context, Intent intent) {
//Toast.makeText(context,"Alarm has been set",Toast.LENGTH_SHORT).show();
NotificationCompat.Builder mNotify=new NotificationCompat.Builder(context);
mNotify.setSmallIcon(R.drawable.index);
mNotify.setContentTitle("Coding");
mNotify.setContentText("INVENTO: Coding competition is going to be conducted today.");
Intent resultIntent=new Intent(context,Coding.class); //activity to open up when user clicks the notification
TaskStackBuilder stackBuilder=TaskStackBuilder.create(context);
stackBuilder.addParentStack(Coding.class); //add the to-be-displayed activity to the top of stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mNotify.setContentIntent(resultPendingIntent);
NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notifyId, mNotify.build());
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
//note: on click display activity is not working.
}
}
请帮忙
我的manifest.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.defcomdevs.invento16" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AlarmActivity"
android:label="@string/title_activity_alarm"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<receiver
android:name=".AlarmReceiver"
android:process=":remote" />
<activity
android:name=".Registration"
android:label="@string/title_activity_registration"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".Coding"
android:label="@string/title_activity_coding"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
</application>
将
android:exported=“true”
添加到manifest.xml文件中的活动标记中。但是请记住,这允许其他应用程序启动您的活动。您还可以包含manifest.xml文件吗?@GSala我已经添加了我的清单文件。因此,我认为您可以通过在清单的活动标记中添加android:exported=“true”
来修复此问题。但是,我不认为这是最好的解决方案,因为这意味着其他应用程序可以启动你的活动。另外,我对接收器中的android:process:remote“
标记表示怀疑。如果没有导出的标记,可能无法从另一个进程启动活动。我会先尝试从接收器中删除android:process:remote“
。先生,删除android:process:remote”
不起作用。还是一样。我还想指出,在我做了一些更改(如添加共享首选项)之后,这一功能曾经起作用,但这是一个单独的活动,与此活动没有联系。我还为通知添加了铃声。这会导致此问题吗?我不认为铃声会导致此问题问题您是否尝试过设置android:exported:“true”
来识别问题?