点击通知后活动不会启动

问题描述:

我在我的应用程序中创建了通知设置。当用户单击通知时,活动Coding应该打开。但它不是。当我检查电话日志时(在Android的工作室控制台)它有它的一些事情是这样的:点击通知后活动不会启动

10-19 19:18:14.598 888-1437/? W/ActivityManager: Permission Denial: starting Intent { flg=0x1000c000 cmp=com.defcomdevs.invento16/.Coding bnds=[0,874][1080,1060] } from null (pid=-1, uid=10169) not exported from 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> 

+0

你还可以包含你的manifest.xml文件吗? – GSala

+0

@GSala我已经添加了我的清单文件。 – Midhun

+0

所以我认为你可以解决这个问题,在清单中的activity标签内添加'android:exported =“true”'。但是,我不认为这是最好的解决方案,因为这意味着其他应用程序可以开始您的活动。另外,我对接收器中的“android:process”:remote“'标签持怀疑态度。也许你不能从没有导出标签的另一个进程开始活动。我会尝试从接收器中首先删除'android:process“:remote”'。 – GSala

添加android:exported="true".Coding活动标签在manifest.xml文件。虽然请记住,这可以让其他应用程序启动您的活动。