简体   繁体   English

单击通知时活动未开始

[英]Activity doesn't start when clicked on the notification

I created a notification setup in my application.when the user clicks the notification an activity Coding is suppose to open.But it isn't.When i checked the phone log(in the console of the android studio) it has some thing like this in it: 我在应用程序中创建了一个通知设置,当用户单击该通知时,假设应该打开一个活动Coding ,但事实并非如此。当我检查电话日志(在android studio的控制台中)时,它有这样的内容在里面:

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

i don't understand what that is? 我不明白那是什么? my code for notification is: 我的通知代码是:

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.
}
}

please help!! 请帮忙!!

My manifest.xml file: 我的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>

Add android:exported="true" to your .Coding activity tag in the manifest.xml file. android:exported="true"添加到manifest.xml文件中的.Coding活动标记中。 Though have in mind that this allows other applications to start your activity. 尽管要记住,这允许其他应用程序开始您的活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM