2017-05-06 5 views
0

mein Handy ist Android 5.0 API 22. Ich lerne gerade App bauen Android ich App gefälschte SMS aber Absturz erstellen :(Security Permission Denial: telephony.SmsProvider uri Inhalt: // sms/Posteingang

java.lang.SecurityException: Permission Denial: writing com.android.providers.telephony.SmsProvider uri content://sms/outbox from pid=23774, uid=10308 requires android.permission.WRITE_SMS, or grantUriPermission() 

Mein Code: MainActivity I Test SMS senden Standard von Telefonnummer 0901123456 und der Mitteilung wünschen auf mein Handy

public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 

public static final String TAG = MainActivity.class.getName(); 
public static final int PERMISSION_RESULT_CODE = 123; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    setupView(); 

    setDefaultApp(); 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
     if (checkSelfPermission(Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) { 
      requestPermissions(new String[]{ 
        Manifest.permission.BROADCAST_SMS, 
        Manifest.permission.READ_SMS, 
        Manifest.permission.SEND_SMS, 
        Manifest.permission.RECEIVE_SMS}, PERMISSION_RESULT_CODE); 
     } 
    } 
} 

private void setupView(){ 
    findViewById(R.id.button_draft).setOnClickListener(this); 
    findViewById(R.id.button_inbox).setOnClickListener(this); 
    findViewById(R.id.button_outbox).setOnClickListener(this); 
    findViewById(R.id.button_sent).setOnClickListener(this); 

} 

private void setDefaultApp(){ 
    final String myPackageName = getPackageName(); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) { 
      Intent intent = 
        new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT); 
      intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, 
        myPackageName); 
      startActivity(intent); 
     } 
    } 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
    if (requestCode == PERMISSION_RESULT_CODE){ 
     for (int i= 0; i< permissions.length; i++) { 
      Log.d(TAG, permissions[i] + " " + grantResults[i]); 
     } 
    } 
    super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
} 


@Override 
public void onClick(View v) { 
    switch(v.getId()){ 

     case R.id.button_draft: 
      ContentValues values1 = new ContentValues(); 
      values1.put("address", "0901123456"); 
      values1.put("body", "test draft"); 
      getContentResolver().insert(Uri.parse("content://sms/draft"), values1); 
      break; 
     case R.id.button_inbox: 
      ContentValues values2 = new ContentValues(); 
      values2.put("address", "0901123456"); 
      values2.put("body", "test inbox"); 
      getContentResolver().insert(Uri.parse("content://sms/inbox"), values2); 
      break; 
     case R.id.button_outbox: 
      ContentValues values3 = new ContentValues(); 
      values3.put("address", "0901123456"); 
      values3.put("body", "test outbox"); 
      getContentResolver().insert(Uri.parse("content://sms/outbox"), values3); 
      break; 
     case R.id.button_sent: 
      ContentValues values4 = new ContentValues(); 
      values4.put("address", "0901123456"); 
      values4.put("body", "test sent"); 
      getContentResolver().insert(Uri.parse("content://sms/sent"), values4); 
      break; 

    } 
} 

}

"test gesendet". 210

AndroidManifest

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.READ_SMS" /> 
<uses-permission android:name="android.permission.SEND_SMS" /> 
<uses-permission android:name="android.permission.RECEIVE_SMS" /> 

<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"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <!-- BroadcastReceiver that listens for incoming SMS messages --> 
    <receiver 
     android:name=".SmsReceiver" 
     android:permission="android.permission.BROADCAST_SMS"> 
     <intent-filter> 
      <action android:name="android.provider.Telephony.SMS_DELIVER" /> 
     </intent-filter> 
    </receiver> 

    <!-- BroadcastReceiver that listens for incoming MMS messages --> 
    <receiver 
     android:name=".MmsReceiver" 
     android:permission="android.permission.BROADCAST_WAP_PUSH"> 
     <intent-filter> 
      <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" /> 
      <data android:mimeType="application/vnd.wap.mms-message" /> 
     </intent-filter> 
    </receiver> 

    <receiver 
     android:name=".FinderReceiver" 
     android:enabled="true" 
     android:permission="android.permission.RECEIVE_SMS"> 
     <intent-filter> 
      <action 
       android:name="android.provider.Telephony.SMS_RECEIVED" 
       android:priority="999" /> 
     </intent-filter> 
    </receiver> 

    <!-- Activity that allows the user to send new SMS/MMS messages --> 
    <activity 
     android:name=".ComposeSmsActivity" 
     android:exported="true"> 
     <intent-filter> 
      <action android:name="android.intent.action.SEND" /> 
      <action android:name="android.intent.action.SENDTO" /> 

      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 

      <data android:scheme="sms" /> 
      <data android:scheme="smsto" /> 
      <data android:scheme="mms" /> 
      <data android:scheme="mmsto" /> 
     </intent-filter> 
    </activity> 

    <!-- Service that delivers messages from the phone "quick response" --> 
    <service 
     android:name=".HeadlessSmsSendService" 
     android:exported="true" 
     android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"> 
     <intent-filter> 
      <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 

      <data android:scheme="sms" /> 
      <data android:scheme="smsto" /> 
      <data android:scheme="mms" /> 
      <data android:scheme="mmsto" /> 
     </intent-filter> 
    </service> 
</application> 

Wer kann mir helfen? : (( Vielen Dank

+0

mir helfen huhuhu :( – ducthangwru

Antwort

Verwandte Themen