जब मैं अपना लॉन्च मोड "सिंगल इंस्टेंस" में खोलता हूं तो मुझे MYApp में ईमेल खोलने में समस्या का सामना करना पड़ रहा है।अनुमति त्रुटि प्राप्त करना java.lang.SecurityException: ईमेल अनुलग्नक नाम प्राप्त करते समय 3.x एंड्रॉइड डिवाइस पर अनुमति अस्वीकार
मैंने नमूना एंड्रॉइड प्रोजेक्ट संलग्न किया है जो ईमेल संलग्नक से फ़ाइल नाम पढ़ता है और इसे स्क्रीन पर प्रदर्शित करता है। ऑनक्रेट के मामले में ठीक काम करता है लेकिन जब ऐप लॉन्च मोड एकल होता है तो न्यूइन्टेंट पर त्रुटि फेंकता है।
Launchmode.java
package your.namespace.launchmode;
public class LaunchModeActivity extends Activity {
private static final int OPEN_ACT = 2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String name = getAttachmetName(getIntent());
if(null != name)
{
TextView textv = (TextView) findViewById(R.id.attachmentnm);
textv.setText(name);
}
}
@Override
protected void onNewIntent(Intent savedInstanceState)
{
super.onNewIntent(savedInstanceState);
String name = getAttachmetName(savedInstanceState);
if(null != name)
{
TextView textv = (TextView) findViewById(R.id.attachmentnm);
textv.setText(name);
}
}
private String getAttachmetName(Intent intent) {
final Uri documentUri = intent.getData();
if(null != documentUri){
final String uriString = documentUri.toString();
String documentFilename = null;
final int mailIndexPos = uriString.lastIndexOf("/attachments");
if (mailIndexPos != -1) {
final Uri curi = documentUri;
final String [] projection = new String[] {OpenableColumns.DISPLAY_NAME};
final Cursor cursor = getApplicationContext().getContentResolver().query(curi, projection, null, null, null);
if (cursor != null) {
final int attIdx = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (attIdx != -1) {
cursor.moveToFirst();
documentFilename = cursor.getString(attIdx);
}
cursor.close();
}
}
return documentFilename;
}
return null;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if((resultCode == RESULT_OK) && (requestCode == OPEN_ACT))
{
Log.d("LaunchMode", "Second activity returned");
}
}
}
AndroidManifest
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.namespace.launchmode"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.gm.permission.WRITE_GMAIL"/>
<uses-permission android:name="com.google.android.providers.gmail.permission.READ_GMAIL"/>
<uses-permission android:name="com.google.android.providers.gmail.permission.WRITE_GMAIL"/>
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:launchMode="singleInstance"
android:name=".LaunchModeActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<!-- docx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" />
<!-- xlsx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<!-- pptx -->
<data android:mimeType="application/vnd.openxmlformats-officedocument.presentationml.presentation" />
<data android:mimeType="application/vnd.ms-excel" />
<data android:mimeType="application/msword" />
<data android:mimeType="application/vnd.ms-powerpoint" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>
कदम पुन: पेश करने 1) डिवाइस पर apk को स्थापित करें। 2) डिवाइस पर जीमेल मूल ऐप पर जाएं, देखने के लिए कोई अनुलग्नक (कार्यालय दस्तावेज़) खोलें। 3) कार्रवाई पूर्ण करने के लिए LaunchMode ऐप चुनें। 4) लॉन्चमोड ऐप स्क्रीन पर फ़ाइल का नाम प्रदर्शित करेगा।
यह पहली बार है (onCreate प्रवाह), लेकिन जब इस एप्लिकेशन को पृष्ठभूमि में स्विच है और फिर मैं 2,3,4 चरणों का प्रयास .. त्रुटि के साथ ऐप्लिकेशन क्रैश
E/DatabaseUtils(30615): java.lang.SecurityException: Permission Denial: reading com.google.android.gm.provider.MailProvider uri content://gmail-ls/[email protected]/messages/5/attachments/0.2/BEST/false from pid=32657, uid=10058 requires com.google.android.gm.permission.READ_GMAIL
E/DatabaseUtils(30615): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:309)
E/DatabaseUtils(30615): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:178)
E/DatabaseUtils(30615): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111)
E/DatabaseUtils(30615): at android.os.Binder.execTransact(Binder.java:339)
E/DatabaseUtils(30615): at dalvik.system.NativeStart.run(Native Method)
D/AndroidRuntime(32657): Shutting down VM
मैं इसे ठीक करने की जरूरत है के लिए ठीक काम करता है क्योंकि, मुझे एप्लिकेशन का एक उदाहरण होना चाहिए और ईमेल संलग्नक नाम भी प्राप्त करना चाहिए। कृपया मुझे बताएं अगर मुझे यहां कुछ याद आ रहा है। 1) 2.x फोन 2) एकल शीर्ष लांच मोड के साथ ठीक काम करता है के साथ ठीक काम करता है:
मेरे यहाँ सवाल क्यों यह onCreate के प्रवाह में काम करते हैं और यह अभ्यस्त onNewIntent
नोट के मामले में काम करते हैं। 3) जीमेल ऐप पर कुछ अपडेट। link here: