HOW CAN I REPLACE THE R.id.ic_launcher with the specific id that user selected.
i have created an application which represents some grid view of images, then after user selection it select the specific image and then a share menu button share the image to the social apps.
but the error is whenever any image is selected and shared to any application it only sends the default launcher icon i.e, ic_launcher.png.
my code goes below like this:
FullImageActivity.java
#SuppressLint("SdCardPath")
public class FullImageActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
Intent i = getIntent();
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
File sd = Environment.getExternalStorageDirectory();
String fileName = "test.png";
File dest = new File(sd, fileName);
try {
FileOutputStream out;
out = new FileOutputStream(dest);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
switch (item.getItemId()) {
case R.id.item:
Uri uri = Uri.fromFile(dest);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share)));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
this is where i implemented the share method, this is shere my code sending the defautl ic_launcher.png instead of selected image.
further i kept all the images in .jpeg format in ImageAdapter.java class.
private Context mContext;
// Keeping all Images in array
public Integer[] mThumbIds = {
R.drawable.rage_0001,R.drawable.rage_0002,
and my AndroidManifest.XML goes like this for all uses permissions and activity records.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:permission="android.permission.WRITE_EXTERNAL_STORAGE"
android:theme="#style/AppTheme" >
<activity
android:name="com.jai.desimeme.MainActivity"
android:label="#string/app_name" >
<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.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- FullImageActivity -->
<activity android:name="com.jai.desimeme.FullImageActivity" >
</activity>
<activity
android:name="com.jai.desimeme.About"
android:theme="#android:style/Theme.Dialog" >
</activity>
<activity
android:name="com.jai.desimeme.ShareActivity"
android:label="#string/title_activity_share" >
</activity>
</application>
tell me where i need to modify my code for proper working as i mentioned above.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),drawable.ic_launcher);//launcher being saved to file
File sd = Environment.getExternalStorageDirectory();
String fileName = "test.png";
File dest = new File(sd, fileName);
try {
FileOutputStream out;
out = new FileOutputStream(dest);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
This is the part where you are saving the launcher image to a file and hence sharing that image
Related
I keep getting this error:
java.lang.NullPointerException: Attempt to invoke virtual method
'android.app.Activity io.branch.referral.Branch.getCurrentActivity()'
on a null object reference
this is the source code:
MainApp.java
public class MainApp extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override public void onStart() {
super.onStart();
try {
Branch.sessionBuilder(this).withCallback(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// option 3: navigate to page
Intent intent = new Intent(MainApp.this, Main2Activity.class);
startActivity(intent);
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}).withData(this.getIntent().getData()).init();
}
catch (Exception e) {
e.printStackTrace();
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
try {
setIntent(intent);
// if activity is in foreground (or in backstack but partially visible) launching the same
// activity will skip onStart, handle this case with reInitSession
Branch.sessionBuilder(this).withCallback(branchReferralInitListener).reInit();
}
catch (Exception ignored) { }
}
private Branch.BranchReferralInitListener branchReferralInitListener = new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject linkProperties, BranchError error) {
// do stuff with deep link data (nav to page, display content, etc)
}
};
}
Main2Activity.java
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
#Override public void onStart() {
super.onStart();
try{
// Branch logging for debugging
Branch.enableLogging();
// Branch object initialization
Branch.getAutoInstance(this);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".MainApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="hello" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_jeVWU2AYfrIjpJmslgNxZgjeAwcUzcqK" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use Branch_Test_Key (useful when simulating installs and/or switching between debug and production flavors) -->
<activity android:name=".MainActivity" />
<activity android:name=".Main2Activity" >
<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="2rerz.app.link" />
<!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website. -->
<data android:scheme="https" android:host="2rerz-alternate.app.link" />
</intent-filter>
</activity>
</application>
This is occurring since you have not implemented a CustomApplication class.
Please implement the same and add the Application class to your Manifest.xml file.
I'm currently working on a simple android app. The idea is, it changes the wallpaper automatically after 12 A.M or when the date is changed. It's working on android Oreo and lower versions, however, it doesn't work on android 9(Pie). However, if I change the date manually from the setting of the phone, it calls the broadcast. I have googled a lot, and some suggested to register the broadcast on your java codes instead of Manifest. Unfortunately, it didn't work.
I have tested this question in Stackoverflow.
First of all, changing the date is not part of implicit broadcasts, secondly, I assumed it is. then I changed the codes but it didn't work.
Now I'm gonna provide some codes of my broadcast:
DailyBroadcastReceiverService
public class DailyBroadcastReceiverService extends Service {
private BroadcastReceiver dailyZekrBr;
private Context context;
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
registerDailyZekrReceiver();
}
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(dailyZekrBr);
dailyZekrBr = null;
}
private void registerDailyZekrReceiver() {
context= this.getApplicationContext();
Log.d("Register", "onStart: Now gonna register the broadcast receiver on Daily Boadcast receiver");
dailyZekrBr = new DailyZekrBroadcastReceiver();
IntentFilter filter = new IntentFilter();
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addAction("android.intent.action.ACTION_TIME_CHANGED");
filter.addAction("android.intent.action.TIME_SET");
filter.addAction("android.intent.action.DATE_CHANGED");
filter.addAction("android.intent.action.TIMEZONE_CHANGED");
this.registerReceiver(dailyZekrBr, filter);
}
}
DailyZekrBroadcastReceiver
public class DailyZekrBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("DailyZekrBroadcast", "onReceive:The broadcast is called ");
DailyZekrHandler.setTodayImage(context);
}
}
setTodayImage
public static void setTodayImage(Context context) {
int todayImage = DailyZekrHandler.nameOfTheWeek();
DisplayMetrics metrics = new DisplayMetrics();
WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
window.getDefaultDisplay().getMetrics(metrics);
Log.d("DailyZekrBroadCast", "trying to change imge: " + todayImage);
if(todayImage != DailyZekrHandler.getTodayImage(context)) {
DailyZekrHandler.storeTodayImage(context);
Bitmap tempbitMap = BitmapFactory.decodeResource(context.getResources(), todayImage);
Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap, metrics.widthPixels, metrics.heightPixels, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(metrics.widthPixels, metrics.heightPixels);
try {
wallpaperManager.setBitmap(bitmap);
Log.d("DailyZekrBroadCast", "today_image: " + todayImage);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ellia.dailyzekr">
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-9778979220370457~9773548477"/>
<receiver android:name=".core.DailyZekrBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_TIME_CHANGED"/>
<action android:name="android.intent.action.TIME_SET"/>
<action android:name="android.intent.action.DATE_CHANGED"/>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
<service android:name=".core.DailyBroadcastReceiverService"/>
<activity android:name=".SplashActivity" android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
</application>
</manifest>
I am trying to send an email upon button click with an attachment stored in internal storage. I tried following this tutorial in implementing a file provider, however every time I try running the app and pressing the button the app crashes and stops working.
I am lost for why that may be. Below is the relevant code:
Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:grantUriPermissions="true"
android:exported="false"
android:authorities="${applicationId}">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths"/>
</provider>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
filepaths.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<paths>
<cache-path name="cache" path="/" />
<files-path name= "files" path="/" />
</paths>
</PreferenceScreen>
MainActivity.java
Button emailBtn = (Button) findViewById(R.id.button);
main = findViewById(R.id.main);//email form button
emailBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bitmap b = Screenshot.takescreenshotOfRootView(main);
ImageView programLogo = (ImageView) findViewById(R.id.imageView);
programLogo.setImageBitmap(b);
File filePath = new File(loadImageFromStorage(saveToInternalStorage(b)), "profile.jpg");
Intent intent = new Intent(Intent.ACTION_SEND, Uri.fromParts(
"mailto","myemail#gmail.com", null));
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri uri = (Uri) FileProvider.getUriForFile(MainActivity.this, BuildConfig.APPLICATION_ID, filePath);
intent.setDataAndType(uri, "application/jpg");
String subject = "please work";
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
}
private String saveToInternalStorage(Bitmap bitmapImage) {
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File mypath = new File(directory, "profile.jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return directory.getAbsolutePath();
}
private String loadImageFromStorage(String path) {
File f = new File(path, "profile.jpg");
return f.getAbsolutePath();
}
This is the error I get:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication234567, PID: 5272
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.myapplication234567/app_imageDir/profile.jpg
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.example.myapplication234567.MainActivity$1.onClick(MainActivity.java:64)
at android.view.View.performClick(View.java:6913)
at android.view.View.performClickInternal(View.java:6890)
at android.view.View.access$3200(View.java:792)
at android.view.View$PerformClick.run(View.java:27158)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:7021)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:486)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:872)
Your message contains this path which appears incorrect: /data/data/com.example.myapplication234567/app_imageDir/profile.jpg/profile.jpg
try catches are your friend.
I am developing an app in API 27, I have a problem in opening a PDF from the asset folder. I have tried lots of different approaches, but still not successful.
When the PDF opens, a blank black screen appears. I checked the file.exist() return false in all steps it returns 'false'.
I really need help about this topic. In addition, I tried both internal and external storage. Also tried different intent tag. But still no luck.
Here is the function I've used.
private void openPDFFiles(String fileName) //fileName is the pdf file name which is keep in assets folder. ex file.pdf
{
AssetManager assetManager = getApplicationContext().getAssets();
InputStream in = null;
OutputStream out = null;
File imagePath = new File(getFilesDir(), "Videos");
File file = new File(imagePath, "1.pdf");
try {
in = assetManager.open(fileName);
out = openFileOutput(file.getName(), MODE_PRIVATE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e) {
System.out.println(e);
}
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(FileProvider.getUriForFile(getApplicationContext(), "com.administrator.siemens.android.fileprovider", file), "application/pdf");
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
} catch (RuntimeException ex) {
Toast.makeText(Document.this, "There's no PDF Reader found in your device", Toast.LENGTH_SHORT).show();
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
System.out.println("1222222222");
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.administrator.siemens">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/me"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.administrator.siemens.android.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepath" />
</provider>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
filepath.xml:
<paths>
<files-path name="my_docs" path="Videos/"/>
</paths>
Really thanks!, if anyone can help me.
Edited:1
I'm making an app with sounds and implementing a bit of code I came across the following error to set the sound to a specific contact
this is the code :
Button b7 = (Button)findViewById(R.id.b7);
b7.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
{
if (click){
cp.showAtLocation(v, Gravity.CENTER, 0, 0);
cp.update(0,0,500,500);
click=false;
}else{
cp.dismiss();
click=true;
}}
return click;}});
b7.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
File folder = new File(Environment.getExternalStorageDirectory() + "/Bizzsound/");
boolean success = false;
if (!folder.exists()) {
success = folder.mkdirs();
}
if (!success) {
} else {
}
File direct = new File("/sdcard/Bizzsound/");
if (!direct.exists()) {
direct.mkdirs();
}
byte[] buffer=null;
InputStream fIn = getBaseContext().getResources().openRawResource(R.raw.b1);
File dir1 = new File ("/sdcard/Bizzsound/");
File f1 = new File(dir1, String.format("b1.mp3"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int size=0;
try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
}
try {
FileOutputStream fos = new FileOutputStream(f1);
fos.write(buffer);
fos.flush();
fos.close();
bos.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File k = new File("/sdcard/Bizzsound/", "b1.mp3");
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "b1.mp3");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(AudioColumns.ARTIST, "artist");
values.put(AudioColumns.IS_RINGTONE, true);
values.put(AudioColumns.IS_NOTIFICATION, true);
values.put(AudioColumns.IS_ALARM, true);
values.put(AudioColumns.IS_MUSIC, false);
Intent intent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
mpButton1 = MediaPlayer.create(getBaseContext(),R.raw.b1);
mpButton1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mpButton1) {
// TODO Auto-generated method stub
mpButton1.start();
mpButton1.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mpButton1) {
mpButton1.release();
};
});
}
});
}});
}
#Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
case (PICK_CONTACT):
if (resultCode == Activity.RESULT_OK) {
Uri contactData = data.getData();
Cursor c = managedQuery(contactData, null, null, null, null);
if (c.moveToFirst()) {
String id = c
.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, id);
File k = new File("/sdcard/Bizzsound/", "b1.mp3");
ContentValues localContentValues = new ContentValues();
String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhone.equalsIgnoreCase("1")) {
Cursor phones = getContentResolver().query
(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
phones.moveToFirst();
String cNumber = phones.getString(phones //error at this line
.getColumnIndex("b1.mp3"));
System.out.println("number is:" + cNumber);
}
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String SDCardRoot1 = (Environment.getExternalStorageDirectory() + "/b1.mp3");
localContentValues.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
localContentValues.put(MediaStore.MediaColumns.TITLE,"b1.mp3");
localContentValues.put(MediaStore.MediaColumns.MIME_TYPE,"audio/*");
localContentValues.put(MediaStore.Audio.Media.ARTIST, "");
localContentValues.put(MediaStore.Audio.Media.IS_RINGTONE, true);
localContentValues.put(AudioColumns.IS_NOTIFICATION, true);
localContentValues.put(AudioColumns.IS_ALARM, true);
localContentValues.put(AudioColumns.IS_MUSIC, false);
localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, id);
localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE, SDCardRoot1);
getContentResolver().update(localUri, localContentValues,
null, null);
Toast.makeText(this, "Ringtone assigned to: " + name, 0).show();
}
}
break;
}
}
}
Now the phone freezes when receiving the call from the contact and getting this error:
the process com.android.phone has been stopped
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bizzsound1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:largeHeap="true" >
<activity
android:name="org.bizzsound1.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.bizzsound1.menu"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="org.bizzsound1.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="org.bizzsound1.Disclamer"
android:screenOrientation="portrait">
</activity>
<activity android:name="com.startapp.android.eula.EULAActivity"
android:theme="#android:style/Theme.Translucent"
android:configChanges="keyboard|keyboardHidden|orientation" />
<activity android:name="com.startapp.android.publish.list3d.List3DActivity"
android:taskAffinity="altervista.org.gapplication1.AppWall"
android:theme="#android:style/Theme" />
<activity android:name="com.startapp.android.publish.AppWallActivity"
android:theme="#android:style/Theme.Translucent" android:taskAffinity="altervista.org.gapplication1.AppWall"
android:configChanges="orientation|keyboardHidden" />
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>