• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2015, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.receiveshare;
18 
19 import android.app.IntentService;
20 import android.content.Intent;
21 import android.os.Handler;
22 import android.util.Log;
23 import android.widget.Toast;
24 
25 public class ReceiveShareService extends IntentService {
26     Handler mHandler;
27 
ReceiveShareService()28     public ReceiveShareService() {
29         super("ReceiveShareService");
30     }
31 
onCreate()32     public void onCreate() {
33         super.onCreate();
34         mHandler = new Handler(getMainLooper());
35     }
36 
37     @Override
onHandleIntent(Intent intent)38     protected void onHandleIntent(Intent intent) {
39         mHandler.post(new Runnable() {
40             @Override public void run() {
41                 Toast.makeText(ReceiveShareService.this, R.string.preparing_to_process_share,
42                         Toast.LENGTH_LONG).show();
43             }
44         });
45         try {
46             // Give the activity a chance to finish.
47             Thread.sleep(5*1000);
48         } catch (InterruptedException e) {
49             e.printStackTrace();
50         }
51 
52         final CharSequence text = ReceiveShare.buildShareInfo(getContentResolver(), intent);
53         mHandler.post(new Runnable() {
54             @Override
55             public void run() {
56                 Toast.makeText(ReceiveShareService.this, text, Toast.LENGTH_LONG).show();
57             }
58         });
59         Log.i("ReceiveShare", text.toString());
60     }
61 }
62