Question

i'm trying notification sample with image from URL. Notification success created , but the application force close with error this

03-06 09:31:41.790: E/AndroidRuntime(13432): FATAL EXCEPTION: AsyncTask #1
    03-06 09:31:41.790: E/AndroidRuntime(13432): java.lang.RuntimeException: An error occured while executing doInBackground()
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.lang.Thread.run(Thread.java:856)
    03-06 09:31:41.790: E/AndroidRuntime(13432): Caused by: java.lang.SecurityException: Requires VIBRATE permission
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.os.Parcel.readException(Parcel.java:1425)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.os.Parcel.readException(Parcel.java:1379)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:302)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.app.NotificationManager.notify(NotificationManager.java:124)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.app.NotificationManager.notify(NotificationManager.java:103)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at com.codeversed.example.Notifications.MainActivity$CreateNotification.doInBackground(MainActivity.java:121)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at com.codeversed.example.Notifications.MainActivity$CreateNotification.doInBackground(MainActivity.java:1)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    03-06 09:31:41.790: E/AndroidRuntime(13432):    ... 5 more

and this part of my code notification

private Notification setBigTextStyleNotification() {
        Bitmap remote_picture = null;

        // Create the style object with BigTextStyle subclass.
        NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();
        notiStyle.setBigContentTitle("Big Text Expanded");
        notiStyle.setSummaryText("Nice big text.");

        remote_picture = getBitmapFromURL(sample_url);

        // Add the big text to the style.
        CharSequence bigText = "This is an example of a large string to demo how much " +
                               "text you can show in a 'Big Text Style' notification.";
        notiStyle.bigText(bigText);

        // Creates an explicit intent for an ResultActivity to receive.
        Intent resultIntent = new Intent(this, ResultActivity.class);

        // This ensures that the back button follows the recommended convention for the back key.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

        // Adds the back stack for the Intent (but not the Intent itself).
        stackBuilder.addParentStack(ResultActivity.class);

        // Adds the Intent that starts the Activity to the top of the stack.
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        return new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setAutoCancel(true)
                .setLargeIcon(remote_picture)
                .setContentIntent(resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "One", resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "Two", resultPendingIntent)
                .addAction(R.drawable.ic_launcher, "Three", resultPendingIntent)
                .setContentTitle("Big Text Normal")
                .setContentText("This is an example of a Big Text Style.")
                .setStyle(notiStyle).build();
    }

    public Bitmap getBitmapFromURL(String strURL) {
        try {
            URL url = new URL(strURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

remote_picture = getBitmapFromURL(sample_url) is to get image from url . how to fix it ? thanks very much and sorry for my english.

Was it helpful?

Solution

Here is you issue:

Caused by: java.lang.SecurityException: Requires VIBRATE permission

You need to add this permission to your android manifest to resolve it

 <uses-permission android:name="android.permission.VIBRATE" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top